import numpy as np
import pandas as pd

s = pd.Series([1, 2, 3, np.nan, 4, None, 5], index=['A', 'B', 'C', 'D', 'E', 'F', 'G'], name='scores')
print(s)
# A    1.0
# B    2.0
# C    3.0
# D    NaN
# E    4.0
# F    NaN
# G    5.0
# Name: scores, dtype: float64

print(s.head())  # 默认取前5行数据
print(s.head(3))

print(s.tail())  # 默认取后5行数据
print(s.head(3))

print(s.describe())
# count    5.000000
# mean     3.000000
# std      1.581139
# min      1.000000
# 25%      2.000000
# 50%      3.000000
# 75%      4.000000
# max      5.000000
# Name: scores, dtype: float64


# 获取元素个数，忽略缺失值
print(s.count())
# 5

print(s.keys())
print(s.index)
# Index(['A', 'B', 'C', 'D', 'E', 'F', 'G'], dtype='object')
# Index(['A', 'B', 'C', 'D', 'E', 'F', 'G'], dtype='object')

print(s.isna())
# A    False
# B    False
# C    False
# D     True
# E    False
# F     True
# G    False
# Name: scores, dtype: bool


print(s.isin([3, 5, 6]))
# A    False
# B    False
# C     True
# D    False
# E    False
# F    False
# G     True
# Name: scores, dtype: bool

print(s.sum())
print(s.mean())
print(s.std())
print(s.var())
print(s.median())

s = s.sort_values()
print(s)

print(s.quantile(0.75))
# 4.0

s['H'] = 4
print(s.mode())  # 众数

print(s.value_counts())
print(s.drop_duplicates())
print(s.unique())
print(s.nunique())

print(s.sort_index())
print(s.sort_values())
